﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SVC.client;
namespace UI.Forms
{
    public partial class 外乎单数据导入 : XtraForm
    {
        DataTable dt = null;
        BindingList<View_whd_d_0> cps;
        public delegate void DoAction(BindingList<View_whd_d_0> whd_0);//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        public 外乎单数据导入()
        {
            InitializeComponent();
            
        }

        private void btne_file_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            openFileDialog1.ShowDialog();
            cps = new BindingList<View_whd_d_0>();
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(openFileDialog1.FileName))
            {
                btne_file.Text = openFileDialog1.FileName;
                dt = Comm.getSheets(openFileDialog1.FileName,checkEdit1.Checked);
                if (dt!=null)
                {
                    lue_sheet.Properties.DataSource = dt;
                    lue_sheet.Properties.DisplayMember = "TABLE_NAME";
                    lue_sheet.Properties.ValueMember = "TABLE_NAME";
                    lue_sheet.EditValue = dt.Rows[0][2];
                }

            }
        }

        private void lue_sheet_EditValueChanged(object sender, EventArgs e)
        {
            gridControl1.DataSource = Comm.ReadExcelToTable(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
            lue_1.Properties.DataSource = Comm.getSheetsCloum(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
            lue_2.Properties.DataSource = Comm.getSheetsCloum(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
            lue_3.Properties.DataSource = Comm.getSheetsCloum(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
            lue_4.Properties.DataSource = Comm.getSheetsCloum(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
            lue_5.Properties.DataSource = Comm.getSheetsCloum(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
        }

        private void btne_file_EditValueChanged(object sender, EventArgs e)
        {
            
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (dxValidationProvider1.Validate())
            {
                DataTable d = gridControl1.DataSource as DataTable;
                for (int i = 0; i < d.Rows.Count; i++)
                {
                    View_whd_d_0 b = new View_whd_d_0();
                    b.用户名称 = d.Rows[i][lue_1.Text].ToString();
                    b.受理单号 = d.Rows[i][lue_2.Text].ToString();
                    try
                    {
                        b.往年缴费 = Convert.ToDecimal(d.Rows[i][lue_3.Text]);
                    }
                    catch
                    {
                    }
                    try
                    {
                        b.实时余额 = Convert.ToDecimal(d.Rows[i][lue_4.Text]);
                    }
                    catch
                    {
                    }
                    
                    b.备注信息 = d.Rows[i][lue_5.Text].ToString();
                    cps.Add(b);

                }
                FatherRefresh(cps);
                this.Close();
            }
        }

        private void 串号导入_Load(object sender, EventArgs e)
        {
            lue_2.Properties.DataSource = my.bw.View_BlankCard(my.ACID);
        }


    }
}